<?php
/**
 * Created by IntelliJ IDEA.
 * User: wanglu
 * Date: 17/4/12
 * Time: 17:43
 */
class App_model extends MYNTModel {
  
    function __construct() {
        parent::__construct();
    }


    public function get_release_apps($start, $length, $vcode, $order_by_createtime) {

        if (!empty($vcode)) {
            $this->db->like('vcode', $vcode);
        }
        
        $orderby = array("createtime" => $order_by_createtime);

        return $this->getPageDataTables($start, $length, self::TABLE_APP_RELEASE, $orderby);
    }


    public function get_i18n($start, $length, $version, $orderby) {

        if (!empty($version)) {
            $this->db->like('version', $version);
        }

        return $this->getPageDataTables($start, $length, self::TABLE_I18N, $orderby);
    }

    
    public function add_i18n($appid, $version, $filename, $url) {
        $data = array(
            'appid' => $appid,
            'version' => $version,
            'filename' => $filename,
            'download_url' => $url,
            'createtime'=> time()
         );
        $this->db->insert(self::TABLE_I18N, $data);
        return $this->db->affected_rows() > 0;
    }

    public function get_i18n_by_id($id) {
        $query = $this->db->get_where(self::TABLE_I18N, array('id' => $id));
        return $query->row_array();
    }

    public function delete_i18n_by_id($id) {
        $this->db->where('id', $id)
            ->delete(self::TABLE_I18N);

        return $this->db->affected_rows();
    }
    
}